import scrapy
from firstproject.items import FirstprojectItem


class QiubaiSpider(scrapy.Spider):
    name = 'qiubai'
    # allowed_domains = ['https://www.qiushibaike.com/']
    start_urls = ['https://www.qiushibaike.com/text/']


    def parse(self, response):
        div_list=response.xpath('//*[@class="col1 old-style-col1"]/div')
        # data=[]
        # for div in div_list:
        #     name=div.xpath('./div[@class="author clearfix"]/a[2]//text()')[1].extract()
        #     content=div.xpath('.//div[@class="content"]//text()').extract()
        #     content=''.join(content)
        #     dic={'name':name,
        #          'content':content
        #          }
        #     data.append(dic)
        # return data
        for div in div_list:
            name=div.xpath('./div[@class="author clearfix"]/a[2]//text()')[1].extract()
            content=div.xpath('.//div[@class="content"]//text()').extract()
            content=''.join(content)
            item = FirstprojectItem()
            item['name']=name
            item['content']=content
            yield item



